<?php

namespace App\library\services;

use App\Http\Controllers\Controller;
use Illuminate\Support\Facades\DB;
class BaseServices
{
    /**
     * Author:Zhongyuan Lu
     * 成功返回
     * @param string $message
     * @param array $data
     * @param int $code
     * @return array
     */
    public static function success($message = '',$data = [],$code = 200)
    {
        return ['code' => $code, 'data' => $data, 'message' => $message];
    }
    /**
     * Author:Zhongyuan Lu
     * 失败返回
     * @param string $message
     * @param array $data
     * @param int $code
     * @return array
     */
    public static function fail($message = '',$data = [],$code = 400)
    {
        return ['code' => $code, 'data' => $data, 'message' => $message];
    }
    /**
     * Author::william
     * 开启事务
     */
    public static function beginTrans()
    {
        DB::beginTransaction();
    }
    /**
     * Author::william
     * 提交事务
     */
    public static function commitTrans()
    {
        DB::commit();
    }
    /**
     * Author::william
     * 关闭事务
     */
    public static function rollbackTrans()
    {
        DB::rollback();
    }
}
